package com.evon.yardmanagement.transformer.transaction;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.List;

import org.dozer.DozerBeanMapper;

import com.evon.yardmanagement.model.Car;
import com.evon.yardmanagement.model.Member;
import com.evon.yardmanagement.model.ParkingSlot;
import com.evon.yardmanagement.transformer.BaseTransformer;
import com.evon.yardmanagement.ui.action.transaction.CarEntryAction;
import com.evon.yardmanagement.ui.dto.ParkingSlotDTO;
import com.evon.yardmanagement.ui.dto.transaction.CarDTO;

public class CarEntryTransformer {
	static DozerBeanMapper mapper = new DozerBeanMapper();
//	static {
//		List myMappingFiles = new ArrayList();
//		try {
//			myMappingFiles.add("dozerMapping.xml");
//			mapper.setMappingFiles(myMappingFiles);
//		} catch (Exception e) {
//			e.printStackTrace();
//		}

//	}

	public static Car transform(CarDTO carDTO) {
		Car transientCar = new Car();

//		 BeanUtils.copyProperties(carDTO, transientCar, new String[] {
//		 "HSC_ID",
//		 "HSC_TS", "HSU_ID", "HSU_TS","parkingSlot" });
		transientCar =  new BaseTransformer<Car, CarDTO>(Car.class, CarDTO.class).transformToModel(carDTO);
//		 ParkingSlot slot = new ParkingSlot();
//		 slot.setId(action.getSelectedParkingId());
//		 transientCar.setParkingSlot(slot);
//		 
//		 Member parkingDriver = new Member();
//		 parkingDriver.setId(action.getSelectedMemberId());
//		 transientCar.setParkingDriver(parkingDriver);
//		 
		 transientCar.setParkingTime(new java.sql.Date(new Date().getTime()));
		 transientCar.setParkingStatus("P");
		 
		 
		return transientCar;

	}

	public static CarDTO transform(Car car) {
		CarDTO transientCar = new CarDTO();

//		 BeanUtils.copyProperties(car, transientCar, new String[] { "HSC_ID",
//		 "HSC_TS", "HSU_ID", "HSU_TS","parkingSlot","keyBin","" });
		return new BaseTransformer<Car, CarDTO>(Car.class, CarDTO.class).transformToDTO(car);
		//mapper.map(car, transientCar);
//		 ParkingSlotDTO parkingDTO = new ParkingSlotDTO();
//		 parkingDTO.setId(car.getParkingSlot().getId());
//		 transientCar.setParkingSlot(parkingDTO);

		//return transientCar;

	}

	public static List<CarDTO> transform(List<Car> cars) {
//		if (cars == null || cars.isEmpty()) {
//			return Collections.EMPTY_LIST;
//		}
//		List<CarDTO> listDTO = new ArrayList<CarDTO>(cars.size());
//		for (Car car : cars) {
//			CarDTO transientCar = new CarDTO();
//
//			 BeanUtils.copyProperties(car, transientCar, new String[] {
//			 "HSC_ID", "HSC_TS", "HSU_ID", "HSU_TS" });
//			//mapper.map(car, transientCar);
//			listDTO.add(transientCar);
//		}
		return new BaseTransformer<Car, CarDTO>(Car.class, CarDTO.class).transformToDTO(cars);
		//return listDTO;

	}

}
